<template>
	<view class="authentication column">
		<view class="flex-1 hb column scrolly mt20">
			<view class="cell_item" v-if="details.status_txt">
				<text class="fs30 bold mb20">审核状态</text>
				<text>{{details.status_txt}}</text>
			</view>
			<view class="cell_item" v-if="details.refuse_reason">
				<text class="fs30 bold mb20">拒绝原因</text>
				<text>{{details.refuse_reason}}</text>
			</view>
			<view class="cell_item">
				<text class="fs30 bold mb20">车行名称</text>
				<u-input v-model="form.name" placeholder="请输入车行名称" border="none" />
			</view>
			<view class="cell_item">
				<text class="fs30 bold mb20">所在地</text>
				<view class="align-center justify-between" @click="navTo('pages/find-car/city',{brand:1})">
					<text v-if="form.province_id">{{cityInfor?.name}}</text>
					<text v-else style="color: #C5C5C5;">请选择所在地</text>
					<u-icon name="arrow-right" />
				</view>
			</view>
			<view class="cell_item">
				<view class="fs30 mb10">
					<text class="bold">营业执照</text>
					<text class="fs24 ml20" style="color: #3F3F3F;">(上传本人姓名营业执照照片，最多2张)</text>
				</view>
				<view class="">
					<custom-upload v-model:value="form.business_license" :maxLength="2" />
				</view>
			</view>
			<view class="cell_item">
				<view class="fs30 mb10">
					<text class="bold">门头照片</text>
					<text class="fs24 ml20" style="color: #3F3F3F;">(上传本人门店门牌照片，最多2张)</text>
				</view>
				<view class="">
					<custom-upload v-model:value="form.images" :maxLength="2" />
				</view>
			</view>
		</view>
		<view class="p35">
			<u-button text="提交" type="primary" :customStyle="{height:'80rpx',borderRadius:'15rpx'}" @click="onSubmit"
				v-if="getUserInfo('is_enterprise_auth')==0||getUserInfo('is_enterprise_auth')==3" />
		</view>
	</view>
</template>

<script setup>
	import {
		onLoad,
		onShow
	} from "@dcloudio/uni-app";
	import {
		ref
	} from "vue";
	import {
		storeApply,
		storeApplyDetails
	} from "@/api/user/index";
	import {
		getUserInfo,
		navBack,
		navTo,
		showSuccess,
		showToast
	} from "@/core/app";

	const cityInfor = ref(null)
	const status_txt = ref(null)
	const details = ref({})
	onLoad(() => {
		if (getUserInfo('is_enterprise_auth') != 0) {
			storeApplyDetails().then(res => {
				for (var key in form.value) {
					form.value[key] = res.data[key]
				}
				details.value = res.data
				cityInfor.value = {
					name: res.data.province_name
				}
			})
		}
	})
	onShow(() => {
		uni.$once('changeCity', (data) => {
			cityInfor.value = JSON.parse(data.brand)
			form.value.province_id = cityInfor.value.id
		});
	})
	const form = ref({
		name: '',
		province_id: '',
		business_license: '',
		images: '',
	})
	const onSubmit = async () => {
		if (!form.value.name) return showToast('请填写车行名称')
		if (!form.value.province_id) return showToast('请选择所在地')
		if (!form.value.business_license) return showToast('请上传营业执照')
		if (!form.value.images) return showToast('请上传门头照片')
		let res = await storeApply(form.value)
		if (res) {
			showSuccess('申请成功')
			setTimeout(() => {
				navBack()
			}, 1000)
		}
	}
</script>

<style lang="scss" scoped>
	.authentication {
		height: 100%;

		.cell_item {
			display: flex;
			flex-direction: column;
			background: #fff;
			margin-bottom: 20rpx;
			padding: 27rpx 30rpx;
		}
	}
</style>